package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.dao.PermissionDao;
import com.itheima.entity.PageResult;
import com.itheima.pojo.Permission;
import com.itheima.service.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @Auther: UniquePiggy
 * @Date: 2020/11/22/11:11
 */
@Service(interfaceClass = PermissionService.class)
@Transactional
public class PermissionServiceImpl implements PermissionService{

    @Autowired
    private PermissionDao permissionDao;

    //分页查询
    @Override
    public PageResult findPage(Integer currentPage, Integer pageSize, String queryString) {
        //设置分页参数
        PageHelper.startPage(currentPage,pageSize);

        Page<Permission> page = permissionDao.findPage(queryString);


        return new PageResult(page.getTotal(),page.getResult());
    }

    //查询所有
    @Override
    public List<Permission> findAll() {
        return permissionDao.findAll();
    }

    //查询与该权限是否已经存在
    @Override
    public int queryCount(Permission permission) {
        return permissionDao.queryCount(permission);

    }

    //新增权限
    @Override
    public void add(Permission permission) {
        permissionDao.add(permission);
    }

    //查询与该权限相关联的角色数
    @Override
    public int connCounts(Integer id) {
        return permissionDao.connCounts(id);
    }

    //删除权限
    @Override
    public void delete(Integer id) {
        permissionDao.delete(id);
    }

    @Override
    public Permission findById(Integer id) {
        return permissionDao.findById(id);
    }

    //修改权限
    @Override
    public void update(Permission permission) {
        permissionDao.update(permission);
    }
}
